<?php
/**
 * Created by PhpStorm.
 * User: 小蛮哼哼哼
 * Email: 243194993@qq.com
 * Date: 2021/11/17
 * Time: 16:57
 * motto: 现在的努力是为了小时候吹过的牛逼！
 */

declare(strict_types=1);

namespace app\common\business;

use app\common\lib\Show;
use app\common\model\mysql\Jianyi as ModelObj;
use app\common\validate\Jianyi as ValObj;
use think\Exception;

class Jianyi extends Base
{
    protected $valObj = null;
    protected $modelObj = null;

    public function __construct()
    {
        $this->valObj = new ValObj();
        $this->modelObj = new ModelObj();
    }

    /**
     * @param array $data
     * @return bool
     * @throws Exception
     */
    public function add(array $data = [])
    {
        if (empty($data['service'])) {
            throw new Exception("请选择服务项目");
        }
        if (!is_array($data['service'])) {
            throw new Exception("服务项目类型错误");
        }
        $service = array_column($data['service'], 'value');
        $data['service'] = Show::json_encode($service);
        return parent::add($data); // TODO: Change the autogenerated stub
    }

    public function addData(array $data = [])
    {
        try {
            $res = $this->modelObj->insertAdd($data);
        } catch (\Exception $e) {
            throw new Exception("操作失败");
        }
        return $res;
    }
}